package com.listviewdemo.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;


/**
 * Created by tzj on 2018/4/25.
 */

public class RnListView extends ListView {

    public RnListView(Context context) {
        this(context,null);
    }

    public RnListView(Context context, AttributeSet attrs) {
        this(context, attrs,-1);
    }

    public RnListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private final Runnable measureAndLayout = new Runnable() {
        @Override
        public void run() {
            if (getWidth() > 0 && getHeight() > 0) {
                measure(
                        MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
                layout(getLeft(), getTop(), getRight(),  getBottom());
            }
        }
    };

    @Override
    protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
        return false;
    }

    @Override
    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
//        super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
    }

    @Override
    public void requestLayout() {
        super.requestLayout();
        post(measureAndLayout);
    }

}
